MAINT Enable ruff rule E (pycodestyle errors)#1413
Conversation
af54821 to
f59ea43
Compare
There was a problem hiding this comment.
Pull request overview
This maintenance PR enables the ruff E rule category (pycodestyle errors) in the linting configuration to enforce code style consistency across the PyRIT codebase. The changes address four specific error types: E402 (module imports not at top of file), E501 (lines exceeding 120 characters), E721 (type comparisons using == instead of is), and E731 (lambda assignments instead of def statements).
Changes:
- Enabled ruff E rule in pyproject.toml to enforce pycodestyle error checks
- Fixed import placement in 3 files (moved
from __future__ import annotationsafter module docstrings, added noqa comment where intentional) - Wrapped long strings and docstrings to comply with 120-character line limit in 11 files
- Changed type comparison from
==toisin test file - Converted lambda assignment to proper function definition in discovery module
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Enabled ruff E rule category in linting configuration |
| pyrit/scenario/core/scenario_strategy.py | Moved from __future__ import annotations after module docstring |
| pyrit/backend/mappers/attack_mappers.py | Moved from __future__ import annotations after module docstring |
| pyrit/cli/pyrit_backend.py | Added noqa:E402 comment for intentional import after sys.stdout.reconfigure |
| tests/unit/score/test_scorer_prompt_validator.py | Shortened docstring to fit 120-character limit |
| pyrit/score/scorer_evaluation/scorer_metrics_io.py | Split long logger.info string across two lines |
| pyrit/score/audio_transcript_scorer.py | Split long logger.info string across two lines |
| pyrit/scenario/scenarios/airt/jailbreak.py | Split long ValueError message across two lines |
| pyrit/prompt_target/openai/openai_target.py | Split long logger.info string across two lines |
| pyrit/prompt_target/openai/openai_image_target.py | Reformatted image_size docstring parameter across multiple lines |
| pyrit/executor/attack/multi_turn/chunked_request.py | Split long request_template docstring across two lines |
| pyrit/datasets/seed_datasets/remote/vlsu_multimodal_dataset.py | Split long User-Agent string across multiple lines using tuple concatenation |
| pyrit/datasets/jailbreak/text_jailbreak.py | Split long ValueError message across two lines |
| pyrit/cli/pyrit_shell.py | Wrapped multiple long strings and command examples with backslash continuations |
| pyrit/backend/routes/attacks.py | Split long Query parameter description across multiple lines |
| tests/unit/executor/attack/multi_turn/test_red_teaming.py | Changed type comparison from == str to is str |
| pyrit/registry/discovery.py | Converted lambda assignment to proper function definition with type hints |
Enable the E rule category covering: - E402: module import not at top of file (fixed docstring placement, noqa for intentional) - E501: line too long (wrapped long strings/docstrings to 120 chars) - E721: type comparison (use 'is' instead of '==') - E731: lambda assignment (converted to def) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f59ea43 to
e011ab4
Compare
noob question: do we already have a pre-commit rule that limits lines to 120 chars? |
This is a good question! Copilot:
|
… main() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…into romanlutz/ruff_e
- Add E402, E501 to doc/ per-file-ignores (notebooks inherently have mid-file imports and long markdown comment lines) - Fix E712: replace '== False' with 'not' in doc/ files - Fix E722: replace bare 'except' with 'except Exception' in doc/ files - Fix E731: replace lambda with def in test file Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enable the E rule category covering: